package broker

import (
  "context"
  "fmt"
  "gitlab.local/backend/proto/dto"
  "manager/bll"
  log "manager/collector/logger"
  "manager/model"
  "manager/utils"
)

var ControlReport = &controlReport{}

// controlHandler 中控上报
type controlReport struct {
}

// HandlerControl 中控上报
func (a *controlReport) HandlerControl(data *dto.Controller) (err error) {
  if data == nil {
    return fmt.Errorf("controlReport HandlerControl data is nil")
  }

  //版本检测，升级版本
  if len(data.FirmwareVersion) > 0 && len(data.Sn) > 0 {
    log.Infof("HandlerControl CheckVersion data:%v", utils.ToJsonString(data))
    _, err = bll.Ota.CheckVersion(context.Background(), &model.OtaCheckVersionRequest{
      SNCode:  data.Sn,
      Version: data.FirmwareVersion,
    })
  }
  return err
}
